package com.sinotn.ks.node.export.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sinotn.SinotnLogger;
import com.sinotn.ks.node.export.process.XlsGradeExpProcess;
import com.sinotn.task.TaskServer;
import com.sinotn.web.ResponseUtil;

/**
 * 成绩导出功能
 * @Title GradeAction.java
 * @Package com.sinotn.ks.node.export.action
 * @Description
 * Copyright: Copyright (c) 2015
 * Company:北京信诺软通
 *
 * @author <a href="mailto:xieqj@sinoth.com">谢启进</a>
 * @date 2020年8月15日 下午6:27:30
 * @version V1.0
 */
@Controller
@RequestMapping(value = "/R/plugin/export/grade")
public class GradeAction {
	@Autowired
	private TaskServer taskServer;

	/*
	 * 导出excel格式成绩
	 */
	@RequestMapping(value = "/xls.jspx")
	public void upload(HttpServletRequest request,HttpServletResponse response){
		try{
			String id=request.getParameter("id");
			String ip=request.getParameter("ip");
			String mac=request.getParameter("mac");
			String version=request.getParameter("version");
			XlsGradeExpProcess process=new XlsGradeExpProcess(id, ip, mac,version);
			this.taskServer.putAsyncTask(process, true);

			StringBuilder sb=new StringBuilder();
			sb.append("{\"state\":0");
			sb.append(",\"id\":\"").append(process.getId()).append("\"}");
			ResponseUtil.renderJson(response, sb.toString());
		}catch(Throwable e){
			SinotnLogger.DEBUG.error("导出excel格式成绩数据发生系统错误",e);
			ResponseUtil.renderJson(response, "{\"state\":1}");
		}
	}
}
